package com.dxq.wan.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.dxq.basic_ui_library.loadSirCallBack.EmptyCallback;
import com.dxq.basic_ui_library.loadSirCallBack.LoadingCallback;
import com.dxq.wan.R;

/**
 * @author zsh
 * @date 2020/3/9.
 * 功能：
 */

public class Tab5Fragment extends BaseFragment {

    private TextView tvContent;
    private String mTitle;

    //调用该方法，创建fragment
    public static Tab5Fragment newInstance(String title) {
        Bundle bundle = new Bundle();
        bundle.putString(BUNDLE_KEY_TITLE, title);
        Tab5Fragment tab5Fragment = new Tab5Fragment();
        tab5Fragment.setArguments(bundle);
        return tab5Fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();
        if(null != arguments) {
            mTitle = arguments.getString(BUNDLE_KEY_TITLE, "");
        }
    }

    @Override
    protected int onCreateFragmentView() {
        return R.layout.fragment_tab;
    }

    @Override
    protected void initView(View view) {
        tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvContent.setText(mTitle);
    }

    @Override
    protected void loadNet() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mBaseLoadService.showCallback(EmptyCallback.class);
            }
        }, 2000);
    }

    @Override
    protected void onNetReload(View v) {
        mBaseLoadService.showCallback(LoadingCallback.class);
    }

    public void changeTitle(String title) {
        if (!isAdded()) return;
        tvContent.setText(title);
    }
}
